package com.pzl.controller;

import com.pzl.entity.Role;
import com.pzl.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * RoleController class
 *
 * @Author panzhenglei
 * @Date 2019/6/8 10:26 AM
 */

@Controller
@RequestMapping("/role")
public class RoleController {


    @Autowired
    private RoleService roleService;

    @RequestMapping("/list.do")
    public ModelAndView findAll(){
        ModelAndView modelAndView = new ModelAndView();

        List<Role> role = roleService.findAll();
        modelAndView.addObject("role",role);
        modelAndView.setViewName("role-list");

        return modelAndView;
    }

    /*@RequestMapping("/save.do")
    public ModelAndView save(String roleName,String roleDesc) throws Exception {

        ModelAndView modelAndView = new ModelAndView();
        Long save = roleService.save(roleName, roleDesc);
        List<Role> role = roleService.findAll();
        modelAndView.addObject("role",role);
        modelAndView.setViewName("role-list");
        return modelAndView;
    }*/

    @RequestMapping("/save.do")
    public ModelAndView save(Role role) throws Exception {

        ModelAndView modelAndView = new ModelAndView();
        Long save = roleService.save(role);
        List<Role> roles = roleService.findAll();
        modelAndView.addObject("role",roles);
        modelAndView.setViewName("role-list");
        return modelAndView;
    }

}
